import React, { Component } from "react";

// 无论什么都是，都不要将input绑定的值设成null或者undefined
class App extends Component {
  state = {
    textValue: "",
  };
  handleChange = (e) => {
    this.setState({
      textValue: e.target.value,
    });
  };
  fn = () => {
    this.setState({
      textValue: undefined,
    });
  };
  render() {
    return (
      <>
        <h2>受控输入空值</h2>
        <input
          type="text"
          value={this.state.textValue}
          onChange={this.handleChange}
        />

        <button onClick={this.fn}>btn</button>
      </>
    );
  }
}

export default App;
